<!--奖励账号流水页面-->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div>
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<!--        <el-form-item prop="payChannel">-->
<!--          <ren-select v-model="dataForm.payChannel" dict-type="pay_channel" placeholder="请选择支付通道"></ren-select>-->
<!--        </el-form-item>-->
        <el-form-item prop="grantStatus">
          <ren-select v-model="dataForm.grantStatus" dict-type="grant_status" placeholder="请选择发放状态"></ren-select>
        </el-form-item>
        <el-form-item prop="userId">
          <el-input v-model="dataForm.userId" type="text" placeholder="请输入用户ID" clearable></el-input>
        </el-form-item>
        <el-form-item prop="formId">
          <el-input v-model="dataForm.formId" type="text" placeholder="请输入订单编号" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-date-picker
              v-model="createDateList"
              type="daterange"
              placeholder="请选择创建日期"
              format="yyyy 年 MM 月 dd 日"
              range-separator="至"
              start-placeholder="开始创建日期"
              end-placeholder="结束创建日期"
              value-format="yyyy-MM-dd"
              class=""
              @change="createCK"
          />
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">查询</el-button>
        </el-form-item>
        <el-form-item v-if="$hasPermission('api:exportUserAccountEdou:export')">
          <el-button @click="exportHandle()" type="info">导出</el-button>
        </el-form-item>
                <el-form-item>
                  <el-button v-if="$hasPermission('api:userAccountEdou:save')" type="primary"
                             @click="addOrUpdateHandle()">
                    新增
                  </el-button>
                </el-form-item>
                <el-form-item>
                  <el-button v-if="$hasPermission('api:userAccountEdou:delete')" type="danger" @click="deleteHandle()">
                    删除
                  </el-button>
                </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('api:userAccountEdou:update')" type="success"
                     @click="putHandle()">奖励发放
          </el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" stripe highlight-current-row
                @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle"
                ref="multipleTable" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="formId" label="订单编号" header-align="center" align="center" width="" show-overflow-tooltip></el-table-column>
        <el-table-column prop="userId" label="用户ID" header-align="center" align="center" width="180" show-overflow-tooltip>
          <template slot-scope="{}" slot="header">
            <!-- 表头名称 -->
            <span>用户信息</span>
            <el-tooltip class="item" effect="dark" placement="top">
              <i class="el-icon-question" style="font-size:16px;"></i>
              <!-- 悬停提示内容 -->
              <div slot="content">
                <div>点击下方名称查看用户详细信息</div>
              </div>
            </el-tooltip>
          </template>
          <template slot-scope="{row}">
            <div class="flex_rows flex_center" @click="showUserList(row['userDTO'])" v-if="row['userDTO']">
              <el-avatar size="large" :src="row['userDTO']['avatar']"></el-avatar>
              <div class="flex_columns" style="margin-left: 10px;">
                <div class="flex_rows" style="text-decoration: underline;cursor: pointer;">ID:{{row['userDTO']['id']}}</div>
                <div class="flex_rows flex_center" style="text-decoration: underline;cursor: pointer;">
                  <div class="ellipsis1" style="max-width: 4em;">
                    {{row['userDTO']['nickname']}}
                  </div>
                  ({{row['userDTO']['identity']}})
                </div>
              </div>
            </div>
            <div v-if="!row['userDTO']">{{row.userId}}</div>
          </template>
        </el-table-column>
<!--        <el-table-column prop="deptId" label="公司信息" header-align="center" align="center"width="">-->
<!--          <template slot-scope="{}" slot="header">-->
<!--            &lt;!&ndash; 表头名称 &ndash;&gt;-->
<!--            <span>公司信息</span>-->
<!--            <el-tooltip class="item" effect="dark" placement="top">-->
<!--              <i class="el-icon-question" style="font-size:16px;"></i>-->
<!--              &lt;!&ndash; 悬停提示内容 &ndash;&gt;-->
<!--              <div slot="content">-->
<!--                <div>点击下方名称查看公司信息</div>-->
<!--              </div>-->
<!--            </el-tooltip>-->
<!--          </template>-->
<!--          <template slot-scope="{row}">-->
<!--            <el-tag size="small" type="info" style="cursor: pointer;" @click="showDepartmentList(row.sysDeptDTO)" v-if="row.sysDeptDTO">{{row.sysDeptDTO.name}}</el-tag>-->
<!--            <div v-if="!row.sysDeptDTO">{{row.deptId}}</div>-->
<!--          </template>-->
<!--        </el-table-column>-->

        <el-table-column prop="orderAmount" label="订单金额" header-align="center" align="center" width="" sortable show-overflow-tooltip>
          <template slot-scope="{row}">
            <div>{{formatNumber(row.orderAmount)}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="tradeNum" label="奖励金额" header-align="center" align="center" width="" sortable show-overflow-tooltip>
          <template slot-scope="{row}">
            <div>{{formatNumber(row.tradeNum)}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="tradeScene" label="奖励备注" header-align="center" align="center" width="" show-overflow-tooltip>
          <template slot-scope="{row}">
            <div size="small" type="info">{{
                $getDictLabel("tradeScene", row.tradeScene)
              }}
            </div>
          </template>
        </el-table-column>
<!--        <el-table-column prop="isManager" label="分公司负责人" header-align="center" align="center" width="140" show-overflow-tooltip>-->
<!--          <template slot-scope="{row}">-->
<!--            <div size="small" type="info">{{-->
<!--                $getDictLabel("isManager", row.isManager)-->
<!--              }}-->
<!--            </div>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column prop="payChannel" label="支付通道" header-align="center" align="center" width="" show-overflow-tooltip>
          <template slot-scope="{row}">
            <div size="small" type="info">{{
                $getDictLabel("pay_channel", row.payChannel)
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="grantStatus" label="发放状态" header-align="center" align="center" width="" show-overflow-tooltip>
          <template slot-scope="{row}">
            <div>
              {{ $getDictLabel("grant_status", row.grantStatus) }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="createDate" label="创建日期" header-align="center" align="center" width=""></el-table-column>
      </el-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
                     layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
                     @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
      <user-order-product-list v-if="isUserOrderProductList" ref="UserOrderProductList" @cancellation="$refs.multipleTable.clearSelection()"></user-order-product-list>
      <!--查看用户信息组件-->
      <com-user-list :visible.sync="showUser" :content="content"></com-user-list>
    </div>

  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './userAccountEdouAddOrUpdate.vue'
import UserOrderProductList from "@/views/modules/service/userOrderProductList.vue";
import {formatNumber} from "../../../utils";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/api/userAccountEdou/page',
        getDataListIsPage: true,
        deleteURL: '/api/userAccountEdou',
        deleteIsBatch: true,
        putURL: '/api/userAccountEdou/profitSharing',
        putIsBatch: true,
        putIsBatchKey: 'id',   // 删除接口，批量状态下由那个key进行标记操作？比如：pid，uid...
        exportURL: '/api/userAccountEdou/exportUserAccountEdou'             // 导出接口，API地址
      },
      showUser:false,                   //是否显示用户信息
      isUserOrderProductList: false,    //订单详情弹窗
      content:{},                       //用户信息内容
      createDateList: [],               //创建时间数组
      dataForm: {
        id: '',                         //id
        tradeNum:'',                    //交易数量
        tradeScene: '',                 //场景：购物商城、积分商城、签到
        tradeType: '',                  //交易：增加、减少
        payChannel:'',                  //支付通道
        grantStatus:'',                 //发放状态
        userId: '',                     //用户ID
        formId: '',                     //业务编号
        createDateStart: '',            //开始创建时间
        createDateEnd: '',              //结束创建时间
        nickname: '',                   //昵称
        mobile: '',                     //用户手机号
      },
      timeList:[]                          //时间戳数组
    }
  },
  components: {
    UserOrderProductList,
    AddOrUpdate
  },
  watch: {
    '$route':'getPath'
  },
  created() {

  },
  mounted() {
    if (this.$route.query.formId){
      this.mixinViewModuleOptions.createdIsNeed = false
      this.dataForm.formId = this.timeList.includes(this.$route.query.time)?'': this.$route.query.formId
      let _this = this
      setTimeout(function() {
        _this.getDataList()//查询数据
      }, 300)
    }else {
      // console.log(this.dataForm)
      this.mixinViewModuleOptions.createdIsNeed = true
      this.getDataList()//查询数据
    }
    this.timeList.push(this.$route.query.time)
  },
  methods: {
    formatNumber,
    //监听路由变化
    getPath(){
      if (this.$route.query.formId){
        this.mixinViewModuleOptions.createdIsNeed = false
        this.dataForm.formId = this.timeList.includes(this.$route.query.time)?'': this.$route.query.formId
        this.getDataList()//查询数据
      }else {
        this.mixinViewModuleOptions.createdIsNeed = true
        this.dataForm.formId = ''
        this.getDataList()//查询数据
      }
      this.timeList.push(this.$route.query.time)
    },
    /*创建时间选择*/
    createCK() {
      if (!this.createDateList){
        this.dataForm.createDateStart = ''
        this.dataForm.createDateEnd = ''
        return
      }
      this.dataForm.createDateStart = this.createDateList[0]
      this.dataForm.createDateEnd = this.createDateList[1]
    },
    //查看订单信息
    getOrderList(item){
      this.$refs.multipleTable.toggleRowSelection(item);
      this.isUserOrderProductList = true
      this.$nextTick(() => {
        this.$refs.UserOrderProductList.dataForm.id = item.formId
        this.$refs.UserOrderProductList.init()
      })
    },
    //显示用户信息
    showUserList(content){
      this.showUser=true;
      this.content= content;
    },
    //奖励发放
    putHandle(id) {
      if (this.mixinViewModuleOptions.putIsBatch && !id && this.dataListSelections.length <= 0) {
        return this.$message({
          message: '请选择发放项',
          type: 'warning',
          duration: 500
        })
      }
      if(this.mixinViewModuleOptions.putIsBatch && !id && this.dataListSelections.length > 0){
        let  is = false
        this.dataListSelections.forEach((item, index) =>{
          if (item.payChannel !== '微信支付' || item.grantStatus!=='微信零钱待发放'){
            is = true
          }
        })
        if(is){
          return this.$message({
            message: '当前批量选中存在微信支付订单类型外或已发放订单！',
            type: 'warning',
            duration: 3000
          })}
      }
      this.$confirm('确认是否执行发放操作，是否继续?', '奖励发放', {
        confirmButtonText: this.$t('confirm'),
        cancelButtonText: this.$t('cancel'),
        type: 'warning'
      }).then(() => {
        this.$http.put(
            `${this.mixinViewModuleOptions.putURL}${this.mixinViewModuleOptions.putIsBatch ? '' : '/' + id}`,
            this.mixinViewModuleOptions.putIsBatch ? id ? [id] : this.dataListSelections.map(item => item[this.mixinViewModuleOptions.putIsBatchKey]) : {},
        ).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              this.query()
            }
          })
        }).catch(() => {})
      }).catch(() => {})
    }
  }
}
</script>
